﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using LGE;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Audio;

namespace Stealth
{
    public class StartScreen : GameScreen
    {
        Vector2 skyPos = new Vector2(640, 360);
        Vector2 cloudPos = new Vector2(0, 234);
        Vector2 buildPos = new Vector2(640, 407);
        Vector2 logoPos = new Vector2(640, 173);
        Vector2 boxPos = new Vector2(640, 519);
        Vector2 bPlayPos = new Vector2(640, 460);
        Vector2 bOptionsPos = new Vector2(640, 520);
        Vector2 bQuitPos = new Vector2(640, 580);
        Texture2D skySprite;
        Texture2D cloudSprite;
        Texture2D buildSprite;
        Texture2D logoSprite;
        Texture2D boxSprite;
        Texture2D bPlaySprite;
        Texture2D bOptionsSprite;
        Texture2D bQuitSprite;
        Texture2D bPlaySpriteSelected;
        Texture2D bOptionsSpriteSelected;
        Texture2D bQuitSpriteSelected;
        Cloud cloud;

        int cursor = 0;

        public StartScreen()
            : base()
        {
            cloudPos -= skyPos;
            buildPos -= skyPos;
            logoPos -= skyPos;
            boxPos -= skyPos;

            skyPos -= skyPos;
        }

        public override void LoadContent()
        {
            cloud = new Cloud(cloudPos);
            skySprite = Engine.Load<Texture2D>("Images\\StartScreen\\sky");
            cloudSprite = Engine.Load<Texture2D>("Images\\StartScreen\\cloud");
            buildSprite = Engine.Load<Texture2D>("Images\\StartScreen\\buildings");
            logoSprite = Engine.Load<Texture2D>("Images\\StartScreen\\logo");
            boxSprite = Engine.Load<Texture2D>("Images\\StartScreen\\box");
            bPlaySprite = Engine.Load<Texture2D>("Images\\StartScreen\\bPlay");
            bOptionsSprite = Engine.Load<Texture2D>("Images\\StartScreen\\bOptions");
            bQuitSprite = Engine.Load<Texture2D>("Images\\StartScreen\\bQuit");
            bPlaySpriteSelected = Engine.Load<Texture2D>("Images\\StartScreen\\bPlaySelected");
            bOptionsSpriteSelected = Engine.Load<Texture2D>("Images\\StartScreen\\bOptionsSelected");
            bQuitSpriteSelected = Engine.Load<Texture2D>("Images\\StartScreen\\bQuitSelected");
            Audio.PlayBGM("Intro");
        }

        public override void Update(GameTime gameTime)
        {
            cloud.Update(gameTime);
            if (Input.KeyPressed(Keys.Up)) { cursor--; Audio.PlayCue("ss_cursor_move"); }
            if (Input.KeyPressed(Keys.Down)) { cursor++; Audio.PlayCue("ss_cursor_move"); }
            cursor = (int)MathHelper.Clamp(cursor, 0, 2);

            if (Input.KeyPressed(Keys.Enter))
            {
                
                Audio.PlayCue("ss_cursor_select");
                switch (cursor)
                {
                    case 0: GameScreenManager.ChangeScreen(new LevelSelectScreen()); break;
                    case 1: break;
                    case 2: Engine.game.Exit(); break;
                }
            }
        }

        public override void Draw(GameTime gameTime, SpriteBatch spriteBatch)
        {
            spriteBatch.Draw(skySprite, skyPos, Color.White);
            cloud.Draw(spriteBatch);
            spriteBatch.Draw(buildSprite, buildPos, Color.White);
            spriteBatch.Draw(logoSprite, logoPos, Color.White);
            spriteBatch.Draw(boxSprite, boxPos, Color.White);

            if (cursor == 0) spriteBatch.Draw(bPlaySpriteSelected, bPlayPos, Color.White);
            else spriteBatch.Draw(bPlaySprite, bPlayPos, Color.White);
            if (cursor == 1) spriteBatch.Draw(bOptionsSpriteSelected, bOptionsPos, Color.White);
            else spriteBatch.Draw(bOptionsSprite, bOptionsPos, Color.White);
            if (cursor == 2) spriteBatch.Draw(bQuitSpriteSelected, bQuitPos, Color.White);
            else spriteBatch.Draw(bQuitSprite, bQuitPos, Color.White);
        }
    }
}